﻿'use strict';

// the storeController contains two objects:
// - store: contains the product list
// - cart: the shopping cart object
function appController($scope, $routeParams, DataService) {

    // get store and cart from service
    $scope.prods = DataService.products;
    $scope.store = DataService.store;
    $scope.cart = DataService.cart;
    //$scope.selected = undefined;
    // use routing to pick the selected product
    if ($routeParams.productSku != null) {
        $scope.product = $scope.store.getProduct($routeParams.productSku);
    }
    $scope.pmgAddToCar = function() {
        console.log("agrengando al carrito " +$scope.sku +"  "+  $scope.name + " packs:" + $scope.packs + " unidades:"+$scope.price);
        console.log($scope.selected);
        
        $scope.cart.addItem($scope.selected.sku,$scope.selected.name,$scope.selected.price,$scope.packs);
        $("#idSelected").focus();
        $scope.packs = 1;
        $scope.unidades = 0;
        $scope.selected = "";
        
        
    }
    
    $scope.hizoEnter= function($event) {
        $event.preventDefault();
        console.log("hizo enter re loco");
        var elem = angular.element($event.srcElement);
        elem.next('input').focus();

    }
    
    $scope.saveShop= function($event) {
        
        var oPedido = new pedido(1,$scope.cart.items);
        EmApp.pedidos.addAndSave(oPedido);
        
        //RIENICIO EL FORMULARIO DE PEDIDO
        $scope.packs = 1;
        $scope.unidades = 0;
        $scope.selected = "";
        $scope.cart.clearItems();
        
        $("#idSelected").focus();
        
    }
    
     
}


var TabsDemoCtrl = function ($scope) {
  $scope.tabs = [
    { title:"Dynamic Title 1", content:"Dynamic content 1" },
    { title:"Dynamic Title 2", content:"Dynamic content 2", disabled: true }
  ];

  $scope.alertMe = function() {
    setTimeout(function() {
      alert("You've selected the alert tab!");
    });
  };

  $scope.navType = 'pills';
};